//
//  GXTableDetailController.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/12/4.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXTableDetailController.h"
#import "TableNumberManager.h"
@interface GXTableDetailController ()
@property (weak, nonatomic) IBOutlet UITextField *deskNumberTF;
@property (weak, nonatomic) IBOutlet UITextField *peopleNumberTF;

@end

@implementation GXTableDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"更改桌位";
    self.view.backgroundColor = kGlobalbgColor;
    [self setUpNavigationBarRightItem];
    [self setUpViewValue];
}
- (void)setUpViewValue
{
    self.deskNumberTF.placeholder =self.model.tabName;
    self.peopleNumberTF.placeholder = [NSString stringWithFormat:@"%@人",self.model.peopleNum];
}
- (void)setUpNavigationBarRightItem
{
    UIButton * rightButton =[UIButton setButtonTitleNormal:@"保存" buttonTintColor:[UIColor whiteColor]];
    [rightButton addTarget:self action:@selector(clickRightItemButton:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
}
- (void)clickRightItemButton:(UIButton *)saveBtn
{
    if (![self judgeTextFieldValue]) {
        return;
    }
    NSString * deskName = [NSString isBlankString:self.deskNumberTF.text]? self.model.tabName:self.deskNumberTF.text;
    NSString * peopleName = [NSString isBlankString:self.peopleNumberTF.text]? self.model.peopleNum:self.peopleNumberTF.text;
    WeakSelf(weakSelf);
    [TableNumberManager changeTableNumberWithDeId:self.model.deId deskName:deskName peopleNum:peopleName success:^(id responseObject) {
            self.model.tabName = deskName;
            self.model.peopleNum = peopleName;
            if (weakSelf.saveBlock) {
                weakSelf.saveBlock(weakSelf.model);
            }
        } fail:^(id responseObject) {
    }];
}
- (BOOL)judgeTextFieldValue
{
    if ([NSString isBlankString:self.deskNumberTF.text]&&[NSString isBlankString:self.peopleNumberTF.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入更改的内容"];
        return NO;
    }
   
    return YES;
}
@end
